<script lang="ts" setup>
import '@/assets/js/adapter.min';
import '@/assets/js/webrtcstreamer';
const ganttInit=()=>{
  gantt.config.touch = "force";
  gantt.init("gantt_here");
  gantt.config.readonly = false // 设置为可编辑
  gantt.config.autosize = true//自适应尺寸
  gantt.config.autofit = true// 表格列宽自适应
  gantt.config.autoscroll = true// 把任务或者连线拖拽到浏览器屏幕外时，自动触发滚动效果
  gantt.config.drag_progress = false//取消任务进度条进度拖动
  //时间栏配置
  gantt.config.scales = [
    { unit: 'month', step: 1, format: '%Y年%m月' },
    { unit: 'day', step: 1, format: '%m/%d' },
  ]
  gantt.config.scale_height = 60;
  //使用中文
  gantt.i18n.setLocale('cn');
  //获取任务时
  gantt.attachEvent("onTaskLoading", (task: any) => {
    console.log('获取到任务:');
    console.log(task);
    return true;
  })
  //拖动任务时
  gantt.attachEvent("onTaskDrag", function (id: number, mode: any, task: any, original: any) {
    console.log('该任务发生拖动事件:');
    console.log(task);
  });

  //甘特图 任务栏更新后 可获取当前任务对象
  gantt.attachEvent("onAfterTaskUpdate", async function (id: number, task: any) {
    //此处自行加上防抖,否则会重复出发
    console.log('该任务发生更新:');
    console.log(id);
    console.log(task);
  });
  gantt.parse({
    "data": [
      {"id": 11, "text": "Project #1", "start_date": "28-03-2023", "duration": "11", "progress": 0.6, "open": true},
      {"id": 1, "text": "Project #2", "start_date": "01-04-2023", "duration": "18", "progress": 0.4, "open": true},
      {
        "id": 2, "text": "Task #1",
        "start_date": "02-04-2023",
        "duration": "8",
        "parent": "1",
        "progress": 0.5,
        "open": true
      },
      {
        "id": 3,
        "text": "Task #2",
        "start_date": "11-04-2023",
        "duration": "8",
        "parent": "1",
        "progress": 0.6,
        "open": true
      },
      {
        "id": 4,
        "text": "Task #3",
        "start_date": "13-04-2023",
        "duration": "6",
        "parent": "1",
        "progress": 0.5,
        "open": true
      },
      {
        "id": 5,
        "text": "Task #1.1",
        "start_date": "02-04-2023",
        "duration": "7",
        "parent": "2",
        "progress": 0.6,
        "open": true
      },
      {
        "id": 6,
        "text": "Task #1.2",
        "start_date": "03-04-2023",
        "duration": "7",
        "parent": "2",
        "progress": 0.6,
        "open": true
      },
      {
        "id": 7,
        "text": "Task #2.1",
        "start_date": "11-04-2023",
        "duration": "8",
        "parent": "3",
        "progress": 0.6,
        "open": true
      },
      {
        "id": 8,
        "text": "Task #3.1",
        "start_date": "14-04-2023",
        "duration": "5",
        "parent": "4",
        "progress": 0.5,
        "open": true
      },
      {
        "id": 9,
        "text": "Task #3.2",
        "start_date": "14-04-2023",
        "duration": "4",
        "parent": "4",
        "progress": 0.5,
        "open": true
      },
      {
        "id": 10,
        "text": "Task #3.3",
        "start_date": "14-04-2023",
        "duration": "3",
        "parent": "4",
        "progress": 0.5,
        "open": true
      },

      {
        "id": 12,
        "text": "Task #1",
        "start_date": "03-04-2023",
        "duration": "5",
        "parent": "11",
        "progress": 1,
        "open": true
      },
      {
        "id": 13,
        "text": "Task #2",
        "start_date": "02-04-2023",
        "duration": "7",
        "parent": "11",
        "progress": 0.5,
        "open": true
      },
      {
        "id": 14,
        "text": "Task #3",
        "start_date": "02-04-2023",
        "duration": "6",
        "parent": "11",
        "progress": 0.8,
        "open": true
      },
      {
        "id": 15,
        "text": "Task #4",
        "start_date": "02-04-2023",
        "duration": "5",
        "parent": "11",
        "progress": 0.2,
        "open": true
      },
      {
        "id": 16,
        "text": "Task #5",
        "start_date": "02-04-2023",
        "duration": "7",
        "parent": "11",
        "progress": 0,
        "open": true
      },

      {
        "id": 17,
        "text": "Task #2.1",
        "start_date": "03-04-2023",
        "duration": "2",
        "parent": "13",
        "progress": 1,
        "open": true
      },
      {
        "id": 18,
        "text": "Task #2.2",
        "start_date": "06-04-2023",
        "duration": "3",
        "parent": "13",
        "progress": 0.8,
        "open": true
      },
      {
        "id": 19,
        "text": "Task #2.3",
        "start_date": "10-04-2023",
        "duration": "4",
        "parent": "13",
        "progress": 0.2,
        "open": true
      },
      {
        "id": 20,
        "text": "Task #2.4",
        "start_date": "10-04-2023",
        "duration": "4",
        "parent": "13",
        "progress": 0,
        "open": true
      },
      {
        "id": 21,
        "text": "Task #4.1",
        "start_date": "03-04-2023",
        "duration": "4",
        "parent": "15",
        "progress": 0.5,
        "open": true
      },
      {
        "id": 22,
        "text": "Task #4.2",
        "start_date": "03-04-2023",
        "duration": "4",
        "parent": "15",
        "progress": 0.1,
        "open": true
      },
      {
        "id": 23,
        "text": "Task #4.3",
        "start_date": "03-04-2023",
        "duration": "5",
        "parent": "15",
        "progress": 0,
        "open": true
      }
    ],
    "links": [
      {"id": "1", "source": "1", "target": "2", "type": "1"},
      {"id": "2", "source": "2", "target": "3", "type": "0"},
      {"id": "3", "source": "3", "target": "4", "type": "0"},
      {"id": "4", "source": "2", "target": "5", "type": "2"},
      {"id": "5", "source": "2", "target": "6", "type": "2"},
      {"id": "6", "source": "3", "target": "7", "type": "2"},
      {"id": "7", "source": "4", "target": "8", "type": "2"},
      {"id": "8", "source": "4", "target": "9", "type": "2"},
      {"id": "9", "source": "4", "target": "10", "type": "2"},
      {"id": "10", "source": "11", "target": "12", "type": "1"},
      {"id": "11", "source": "11", "target": "13", "type": "1"},
      {"id": "12", "source": "11", "target": "14", "type": "1"},
      {"id": "13", "source": "11", "target": "15", "type": "1"},
      {"id": "14", "source": "11", "target": "16", "type": "1"},
      {"id": "15", "source": "13", "target": "17", "type": "1"},
      {"id": "16", "source": "17", "target": "18", "type": "0"},
      {"id": "17", "source": "18", "target": "19", "type": "0"},
      {"id": "18", "source": "19", "target": "20", "type": "0"},
      {"id": "19", "source": "15", "target": "21", "type": "2"},
      {"id": "20", "source": "15", "target": "22", "type": "2"},
      {"id": "21", "source": "15", "target": "23", "type": "2"}
    ]
  });
  console.log(gantt.getLinks())
}

let webRtcServer=null as any;
const initPlayer=(url:any)=>{
  if (_.isEmpty(url)) return;
  destroyWebRtcServer()
  nextTick(()=>{
    // rtc_player：需要绑定的video控件ID
    // 127.0.0.1:8010：启动webrtc-streamer的设备IP和端口，默认8000
    webRtcServer = new WebRtcStreamer('rtc_player', location.protocol + `//192.168.1.72:8000`)
    // 需要查看的rtsp地址
    webRtcServer.connect(url)
  })
}
const destroyWebRtcServer=()=>{
  webRtcServer && webRtcServer.disconnect()
  webRtcServer = null
}
onMounted(() => {
  // ganttInit();
  initPlayer('rtsp://192.168.1.72/ch1');
})
</script>
<template>
<!--  <div id="gantt_here" class="w-full h-full"></div>-->
  <div class="video-box">
    <video id="rtc_player" controls muted autoplay class="video-player"></video>
  </div>
</template>

<style lang="scss" scoped>

</style>